package com.example.tutobdd;

import android.app.ActionBar;
import android.app.Activity;
import android.app.FragmentTransaction;
import android.app.ListActivity;
import android.content.ClipData;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

import java.util.ArrayList;

//Choiti listActivity pour simplifier l'écriture de l 'a ctivité
public class MyActivity extends ListActivity implements ActionBar.TabListener  {
    private BDD bdd;
    Cursor cListeInfos;
    public ActionBar actionBar;
    private String[] tabs = { "Top Rated", "Games", "Movies" };



    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        bdd = new BDD();
        bdd.open(this);

        // Action BAR

        // TEST 1
        actionBar = getActionBar();

        // Hide the action bar title
        actionBar.setDisplayShowTitleEnabled(true);

        // Enabling Spinner dropdown navigation
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
        /*actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME
                | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setSubtitle("mytest");
        actionBar.setTitle("MENU");*/
        // END TEST1




        // actionBar.show();

        for (String tab_name : tabs) {
            actionBar.addTab(actionBar.newTab().setText(tab_name)
                    .setTabListener(this));
        }




        // requete
        cListeInfos = bdd.getinfos();
        startManagingCursor(cListeInfos);
        // c'est mieux d'utiliser CursorLoader si api > 18 (4.3) sinon utilise toujours startManagingCursor




        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_2,cListeInfos,new String[]{"info","_id"},new int[]{android.R.id.text1,android.R.id.text2});

        setListAdapter(adapter);


    }

    @Override

        public void onListItemClick(ListView l , View v,int position,long idInfo){

        super.onListItemClick(l,v,position,idInfo);
        Log.i("TUTO", "click " + idInfo);
    }
    /*@Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
        menu.setHeaderTitle("Context Menu");
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_optionsmenu, menu);



    }*/

    @Override

        public boolean onCreateOptionsMenu(Menu menu){
        super.onCreateOptionsMenu(menu);

        Log.e(" MEEEEEEE " , " call create option menu");

        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main_optionsmenu,menu);

        return true;
    }

    @Override
    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {

    }

    @Override
    public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {

    }

    @Override
    public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {

    }
}
